package pervasivePositioning.androidPositioner;

import java.io.IOException;

import android.app.Activity;
import android.util.Log;
import android.widget.TextView;

//Client class for the Pervasive Positioning Project 2
public class AndroidPositioner implements Runnable {
	
	private ReportingStrategy _strategy;
	private PositionService _service;
	private Activity _activity;
	
	public AndroidPositioner(Activity activity) {
		_activity = activity;
	}
	
    public void run() 
    {
    	TextView tv = new TextView(_activity);
		_activity.setContentView(tv);
		tv.append("AndroidPositioner Thread Running\n");
    	try {
    		tv.append("Initialising TCPPositionService\n");
				_service = new TCPPositionService("192.168.1.2", 5432);
			//_service.initializeCommunicator();
			tv.append("TCPPositionService initialised\n");
			tv.append("Initialising Strategy\n");
	        _strategy = new PeriodicStrategy(_activity, _service);
	        tv.append("Strategy Initialised\n");
	        tv.append("Starting Strategy\n");
	        get_strategy().Start();
	        tv.append("Strategy started\n");
	        tv.append("Stopping Strategy\n");
	    	get_strategy().Stop();
	    	tv.append("Strategy stopped\n");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			tv.append(e.getLocalizedMessage());
			Log.e("AndroidPositioner.run",e.getLocalizedMessage());
		}
		
    }

	public void set_strategy(ReportingStrategy _strategy) {
		this._strategy = _strategy;
	}

	public ReportingStrategy get_strategy() {
		return _strategy;
	}

	public void set_service(PositionService _service) {
		this._service = _service;
	}

	public PositionService get_service() {
		return _service;
	}

	public void set_activity(Activity _activity) {
		this._activity = _activity;
	}

	public Activity get_activity() {
		return _activity;
	}
}